package com.persistence.dao;

/*******************************************************************************
*DOCUMENT ME!
*
*@author  Diego Iacono
*@since
*******************************************************************************/
public class ShoeMakerException extends Exception
{
    private static final long serialVersionUID = 1L;
    private static final String NEW_LINE = "\n";
    private Throwable initial = null;
    private MessageError messageError = null;

    /***************************************************************************
    Creates a new EdsException object.
    ***************************************************************************/
    public ShoeMakerException()
    {
        super();
    }


    /***************************************************************************
    Creates a new EdsException object.

    @param  message  DOCUMENT ME!
    ***************************************************************************/
    public ShoeMakerException(String message)
    {
        super(message);
    }


    /***************************************************************************
    Creates a new EdsException object.

    @param  initial  DOCUMENT ME!
    ***************************************************************************/
    public ShoeMakerException(Throwable initial)
    {
        this(null, initial, null);
    }


    /***************************************************************************
    Creates a new EdsException object.

    @param  message  DOCUMENT ME!
    ***************************************************************************/
    public ShoeMakerException(MessageError message)
    {
        this();
        setMessage(message);
    }


    /***************************************************************************
    Creates a new EdsException object.

    @param  messageError  DOCUMENT ME!
    @param  initial       DOCUMENT ME!
    ***************************************************************************/
    public ShoeMakerException(MessageError messageError, Throwable initial)
    {
        this(null, initial, messageError);
    }


    /***************************************************************************
    Creates a new EdsException object.

    @param  message  DOCUMENT ME!
    @param  initial  DOCUMENT ME!
    ***************************************************************************/
    public ShoeMakerException(String message, Throwable initial)
    {
        this(message);
        setInitial(initial);
    }


    /***************************************************************************
    Creates a new EdsException object.

    @param  message       DOCUMENT ME!
    @param  initial       DOCUMENT ME!
    @param  messageError  DOCUMENT ME!
    ***************************************************************************/
    public ShoeMakerException(String message, Throwable initial, MessageError messageError)
    {
        this(message, initial);
        setMessageError(messageError);
    }

    /***************************************************************************
    DOCUMENT ME!

    @return  DOCUMENT ME!
    ***************************************************************************/
    public String getChainMessages()
    {
        StringBuffer msg = new StringBuffer();

        msg.append(this.getMessage());

        if (getInitial() != null)
        {
            msg.append(NEW_LINE + "Causa: " + NEW_LINE);

            if ((getInitial() != null) && (getInitial() instanceof ShoeMakerException))
            {
                msg.append(((ShoeMakerException)getInitial()).getChainMessages());
            }
            else if (getInitial() != null)
            {
                msg.append(getInitial().getMessage());
            }
        }

        return msg.toString();
    }


    /***************************************************************************
    DOCUMENT ME!

    @return  DOCUMENT ME!
    ***************************************************************************/
    protected Throwable getInitial()
    {
        return initial;
    }


    /***************************************************************************
    DOCUMENT ME!

    @param  initial  DOCUMENT ME!
    ***************************************************************************/
    protected void setInitial(Throwable initial)
    {
        this.initial = initial;
    }


    /***************************************************************************
    DOCUMENT ME!

    @return  DOCUMENT ME!
    ***************************************************************************/
    public MessageError getMessageError()
    {
        return messageError;
    }


    /***************************************************************************
    DOCUMENT ME!

    @param  messageError  DOCUMENT ME!
    ***************************************************************************/
    public void setMessage(MessageError messageError)
    {
        this.messageError = messageError;
    }


    /***************************************************************************
    DOCUMENT ME!

    @param  messageError  DOCUMENT ME!
    ***************************************************************************/
    public void setMessageError(MessageError messageError)
    {
        this.messageError = messageError;
    }
}
